﻿using System;
using System.Data;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AnyOffice.Components;
using AnyOffice.DAL;
using AnyOffice.Model;

namespace AnyOffice.general.address.personal
{
    public partial class address_new : ModulePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.Page.IsPostBack)
            {
                int num = (Request.QueryString["group_id"] == null) ? 0 : int.Parse(Request.QueryString["group_id"].ToString());
                this.ViewState["GroupId"] = num;
                ListItem item = new ListItem("默认", "0");
                if (num.ToString() == "0")
                {
                    item.Selected = true;
                }
                this.ddlGroupId.Items.Add(item);
                DataTable table = new AddressGroupDao().SelectAll(base.Conn, base.User.Identity.Name);
                if (table.Rows.Count > 0)
                {
                    for (int i = 0; i < table.Rows.Count; i++)
                    {
                        item = new ListItem(table.Rows[i]["GroupName"].ToString(), table.Rows[i]["GroupId"].ToString());
                        if (num.ToString() == table.Rows[i]["GroupId"].ToString())
                        {
                            item.Selected = true;
                        }
                        this.ddlGroupId.Items.Add(item);
                    }
                }
            }
            if (this.Page.IsPostBack)
            {
                this.pnlMain.Visible = false;
                AddressDao dao2 = new AddressDao();
                AddressData data = new AddressData();
                data.UserId = base.User.Identity.Name;
                data.GroupId = Convert.ToInt32(this.ddlGroupId.SelectedValue);
                data.Name = this.txtName.Value;
                //data.Sex = Convert.ToBoolean(this.ddlSex.SelectedValue);
                //data.Birthday = this.txtBirthday.Value;
                data.NickName = this.txtNickName.Value;
                data.Ministration = this.txtMinistration.Value;
                //data.Mate = this.txtMate.Value;
                //data.Child = this.txtChild.Value;
                //data.DeptName = this.txtDeptName.Value;
                //data.DeptAddr = this.txtDeptAddr.Value;
                //data.DeptPost = this.txtDeptPost.Value;
                data.DeptTel = this.txtDeptTel.Value;
                data.DeptFax = this.txtDeptFax.Value;
                data.HomeAddr = this.txtHomeAddr.Value;
                //data.HomePost = this.txtHomePost.Value;
                //data.HomeTel = this.txtHomeTel.Value;
                data.Mobile = this.txtMobile.Value;
                //data.Bp = this.txtBp.Value;
                //data.Email = this.txtEmail.Value;
                //data.Oicq = this.txtOicq.Value;
                //data.Msn = this.txtMsn.Value;
                data.Note = this.txtNote.Value;
                dao2.Insert(base.Conn, data);
                StringBuilder builder = new StringBuilder("<script>\n");
                builder.Append("parent.menu.location.reload();\n");
                builder.Append("parent.main.location='address.aspx?group_id=" + this.ddlGroupId.SelectedValue + "';\n");
                builder.Append("</script>\n");
                if (!this.Page.IsClientScriptBlockRegistered("AddressGroup_list"))
                {
                    this.Page.RegisterClientScriptBlock("AddressGroup_list", builder.ToString());
                }
            }
        }


    }
}
